/**
 * Copyright (c) 2010
 * Bert Young. UESTC. 
 */

#ifndef BERT_SINGLETON_H
#define BERT_SINGLETON_H

#include <cstdio>
#include "Noncopyable.h"
/**
 * Singleton Pattern
 */
template <typename T>
class Singleton : private Noncopyable
{
protected:
	/**
	 * Constructor
	 */
	Singleton() { }
	/**
	 * Destructor
	 */
	~Singleton() { }
	/**
	 * The unique instance
	 */
	static T * instance;
	
public:
	/**
	 * Create instance
	 */
	static void creatInstance()
	{
		if ( instance == NULL )
			instance = new T();
	}
	/**
	 * The global access point
	 */
	static T * getInstance()
	{
		return instance;
	}
	/**
	 * Delete instance 
	 */
	static void delInstance()
	{
		delete instance;
		instance = NULL;
	}
};

template <typename T>
T * Singleton<T>::instance = NULL;

#endif
